<html>
<head>
<title>shopping_cart.py</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.s0 { color: #000000;}
.s1 { color: #008080; font-weight: bold;}
.s2 { color: #0000ff;}
.s3 { color: #000080; font-weight: bold;}
</style>
</head>
<body bgcolor="#ffffff">
<table CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#c0c0c0" >
<tr><td><center>
<font face="Arial, Helvetica" color="#000000">
shopping_cart.py</font>
</center></td></tr></table>
<pre>product_list = [
    (<span class="s1">'HUAWEI P30'</span>, <span class="s2">3800</span>),
    (<span class="s1">'Macbook pro'</span>, <span class="s2">16000</span>),
    (<span class="s1">'Nike'</span>, <span class="s2">850</span>),
    (<span class="s1">'milk tea'</span>, <span class="s2">15</span>),
    (<span class="s1">'Head first Python'</span>, <span class="s2">128</span>),
    (<span class="s1">'crabs'</span>, <span class="s2">88</span>),
]
shopping_cart = []
Alipay_balance = input(<span class="s1">&quot;Alipay_balance：&quot;</span>)
<span class="s3">while True</span>:
    <span class="s3">for </span>item <span class="s3">in </span>product_list:
       print(product_list.index(item),item)
    user_choice = input(<span class="s1">&quot;请选择商品编号:&quot;</span>)
    <span class="s3">if </span>user_choice.isdigit():
        user_choice =int(user_choice)
        <span class="s3">if </span>user_choice&gt;=<span class="s2">0 </span><span class="s3">and </span>user_choice&lt;<span class="s2">6</span>:
          product_item =  product_list[user_choice]
          <span class="s3">if </span>Alipay_balance &gt;= product_item[<span class="s2">1</span>]:
              Alipay_balance = Alipay_balance - product_item[<span class="s2">1</span>]
              shopping_cart.append(product_item)
              print(<span class="s1">&quot;added %s to your shopping cart,your current Alipay balance is %s&quot; </span>%(product_item[<span class="s2">0</span>],Alipay_balance))
        <span class="s3">else</span>:
            print(<span class="s1">&quot;您的余额不足，请使用花呗或购买其他商品。您的余额为：%s&quot; </span>%(Alipay_balance))
    <span class="s3">elif </span>user_choice == <span class="s1">&quot;q&quot;</span>:
        print(<span class="s1">&quot;--------shopping list-------&quot;</span>)
        <span class="s3">for </span>item2 <span class="s3">in </span>shopping_cart:
            print(item2)
            print(<span class="s1">&quot;Alipay_balance: %s&quot; </span>%(Alipay_balance))
        <span class="s3">break</span>
    <span class="s3">else</span>:
        print(<span class="s1">&quot;您输入的商品不存在，请输入正确的商品编号：&quot;</span>)</pre>
</body>
</html>